package org.apcs.pokemon.mechanics;

/**
 * Author:          Zachary Reed
 * Date Created:    Mar 24, 2010
 * Last Modified:   Apr 14, 2010
 * Package:         org.apcs.pokemon.mechanics
 * Filename:        Type.java
 * Description:     A class to hold data about types and type relationships,
 *                  provide methods related to using types.
 */

public class Type {

	/** Array of type names. */
	private static final String[] arrNames = {
		"Normal","Fire","Water","Grass","Electric","Ice","Fighting","Poison",
		"Ground","Flying","Psychic","Bug","Rock","Ghost","Dragon","Dark","Steel"};

	/** Two-dimensional array containing type strength/weakness relationships.
	 * For [x,y]: x=attacking,y=defending */
	private static final double[][] arrTable = {
		{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.5,0.0,1.0,1.0,0.5},	// 0=Normal
		{1.0,0.5,0.5,2.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,2.0,0.5,1.0,0.5,1.0,2.0},	// 1=Fire
		{1.0,2.0,0.5,0.5,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,2.0,1.0,0.5,1.0,1.0},	// 2=Water
		{1.0,0.5,2.0,0.5,1.0,1.0,1.0,0.5,2.0,0.5,1.0,0.5,2.0,1.0,0.5,1.0,0.5},	// 3=Grass
		{1.0,1.0,2.0,0.5,0.5,1.0,1.0,1.0,0.0,2.0,1.0,1.0,1.0,1.0,0.5,1.0,1.0},	// 4=Electric
		{1.0,0.5,0.5,2.0,1.0,0.5,1.0,1.0,2.0,2.0,1.0,1.0,1.0,1.0,2.0,1.0,0.5},	// 5=Ice
		{2.0,1.0,1.0,1.0,1.0,2.0,1.0,0.5,1.0,0.5,0.5,0.5,2.0,0.0,1.0,2.0,2.0},	// 6=Fighting
		{1.0,1.0,1.0,2.0,1.0,1.0,1.0,0.5,0.5,1.0,1.0,1.0,0.5,0.5,1.0,1.0,0.0},	// 7=Poison
		{1.0,2.0,1.0,0.5,2.0,1.0,1.0,2.0,1.0,0.0,1.0,0.5,2.0,1.0,1.0,1.0,2.0},	// 8=Ground
		{1.0,1.0,1.0,2.0,0.5,1.0,2.0,1.0,1.0,1.0,1.0,2.0,0.5,1.0,1.0,1.0,0.5},	// 9=Flying
		{1.0,1.0,1.0,1.0,1.0,1.0,2.0,2.0,1.0,1.0,0.5,1.0,1.0,1.0,1.0,0.0,0.5},	// 10=Psychic
		{1.0,0.5,1.0,2.0,1.0,1.0,0.5,0.5,1.0,0.5,2.0,1.0,1.0,0.5,1.0,2.0,0.5},	// 11=Bug
		{1.0,2.0,1.0,1.0,1.0,2.0,0.5,1.0,0.5,2.0,1.0,2.0,1.0,1.0,1.0,1.0,0.5},	// 12=Rock
		{0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,2.0,1.0,0.5,0.5},	// 13=Ghost
		{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,0.5},	// 14=Dragon
		{1.0,1.0,1.0,1.0,1.0,1.0,0.5,1.0,1.0,1.0,2.0,1.0,1.0,2.0,1.0,0.5,0.5},	// 15=Dark
		{1.0,0.5,0.5,1.0,0.5,2.0,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,0.5}};	// 16=Steel

	/**
     * Return the name of a type.
     *
     * @param type Index value of type.
     * @return The nama of the type as a string
     */
	public static final String getName(int type) {return arrNames[type];}

	/**
     * Calculate attack multiplier, if pokemon has only one type, type1 should
	 * equal type2.
     *
     * @param mtype Move type
     * @param ptype Array containing Pokemon types
	 */
	public static final double getMultiplier(int mtype,int[] ptype) {
		if (ptype[0] == ptype[1]) {return arrTable[mtype][ptype[0]];}
		else {return (arrTable[mtype][ptype[0]] * arrTable[mtype][ptype[1]]);}
	}
}
